package org.eclipse.football;

import static org.junit.Assert.*;

import java.util.ArrayList;

import org.junit.Test;

public class SortTeams {

	@Test
	public void test() {
		// Instantiate a league
		League league = new League("does_not_exist.txt");
		
		// Instantiate 3 teams
		Team team1 = new Team("team1","user1");
		Team team2 = new Team("team2","user2");
		Team team3 = new Team("team3","user3");
		
		// Create 1 OffPlayer, 1 DefPlayer, and 1 kicker per team
		OffPlayer off_player1 = new OffPlayer("off_player1", "team");
		OffPlayer off_player2 = new OffPlayer("off_player2", "team");
		OffPlayer off_player3 = new OffPlayer("off_player3", "team");
		DefPlayer def_player1 = new DefPlayer("def_player1", "team");
		DefPlayer def_player2 = new DefPlayer("def_player2", "team");
		DefPlayer def_player3 = new DefPlayer("def_player3", "team");
		Kicker kicker1 = new Kicker("kicker1", "team");
		Kicker kicker2 = new Kicker("kicker2", "team");
		Kicker kicker3 = new Kicker("kicker3", "team");
		
		// Add stats to each offensive player
		off_player1.setPass_yds(100);
		off_player2.setPass_yds(200);
		off_player3.setPass_yds(300);
		off_player1.setPass_tds(3);
		off_player2.setPass_tds(2);
		off_player3.setPass_tds(0);
		off_player1.setPicks(2);
		off_player2.setPicks(1);
		off_player3.setPicks(0);
		off_player1.setRush_yds(120);
		off_player2.setRush_yds(50);
		off_player3.setRush_yds(10);
		off_player1.setRush_tds(1);
		off_player2.setRush_tds(2);
		off_player3.setRush_tds(3);
		off_player1.setRec_yds(100);
		off_player2.setRec_yds(50);
		off_player3.setRec_yds(20);
		off_player1.setRec_tds(0);
		off_player2.setRec_tds(1);
		off_player3.setRec_tds(2);
		off_player1.setFumbles(0);
		off_player2.setFumbles(1);
		off_player3.setFumbles(2);
		off_player1.setRet_tds(1);
		off_player2.setRet_tds(2);
		off_player3.setRet_tds(3);
		
		// Add stats to defensive players
		def_player1.setDef_tds(2);
		def_player2.setDef_tds(1);
		def_player3.setDef_tds(0);
		def_player1.setPicks(0);
		def_player2.setPicks(1);
		def_player3.setPicks(2);
		def_player1.setFumbles(2);
		def_player2.setFumbles(1);
		def_player3.setFumbles(0);
		def_player1.setSacks(0);
		def_player2.setSacks(3);
		def_player3.setSacks(5);
		def_player1.setBlocks(2);
		def_player2.setBlocks(1);
		def_player3.setBlocks(0);
		def_player1.setSafeties(0);
		def_player2.setSafeties(1);
		def_player3.setSafeties(2);
		def_player1.setPa(0);
		def_player2.setPa(10);
		def_player3.setPa(20);
		def_player1.setYa(400);
		def_player2.setYa(200);
		def_player3.setYa(100);
		
		// Add stats to kickers
		kicker1.setPat(1);
		kicker2.setPat(2);
		kicker3.setPat(0);
		kicker1.setFg(0);
		kicker2.setFg(1);
		kicker3.setFg(2);
		kicker1.setMisses(0);
		kicker2.setMisses(1);
		kicker3.setMisses(2);
		
		// Add players to corresponding teams
		team1.addOffPlayer(off_player1);
		team1.addDefPlayer(def_player1);
		team1.addKicker(kicker1);
		team2.addOffPlayer(off_player2);
		team2.addDefPlayer(def_player2);
		team2.addKicker(kicker2);
		team3.addOffPlayer(off_player3);
		team3.addDefPlayer(def_player3);
		team3.addKicker(kicker3);
		
		// Add teams to league
		league.addTeam(team1);
		league.addTeam(team2);
		league.addTeam(team3);
		
		// Sort teams by pass_yds
		league.sort(0);
		
		// Get this leagues teams array
		ArrayList<Team> teams = league.getTeams();
		
		// Iterate from first team in league to second to last team in league
		for(int i = 0; i < teams.size() - 1; i++){
			// Make sure this team's pass_yds are not less than the next teams
			assertTrue(!(teams.get(i).getPassYds() < teams.get(i+1).getPassYds()));
//			if(teams.get(i).getPassYds() < teams.get(i+1).getPassYds()){
//				// If not then fail
//				fail("Team's were not sorted correctly by passing yards\n");
//			}
		}
		
		// Sort teams by pass_tds
		league.sort(1);
		
		// Get this leagues teams array
		teams = league.getTeams();
		
		// Iterate from first team in league to second to last team in league
		for(int i = 0; i < teams.size() - 1; i++){
			// Make sure this team's pass_tds are not less than the next teams
			assertTrue(!(teams.get(i).getPassTds() < teams.get(i+1).getPassTds()));
//			if(teams.get(i).getPassTds() < teams.get(i+1).getPassTds()){
//				// If not then fail
//				fail("Team's were not sorted correctly by passing touchdowns\n");
//			}
		}
		
		// Sort teams by picks
		league.sort(2);
				
		// Get this leagues teams array
		teams = league.getTeams();
				
		// Iterate from first team in league to second to last team in league
		for(int i = 0; i < teams.size() - 1; i++){
			// Make sure this team's picks are not more than the next teams
			assertTrue(!(teams.get(i).getPicks() > teams.get(i+1).getPicks()));
//			if(teams.get(i).getPicks() > teams.get(i+1).getPicks()){
//				// If not then fail
//				fail("Team's were not sorted correctly by picks\n");
//			}
		}
		
		// Sort teams by rush_yds
		league.sort(3);
				
		// Get this leagues teams array
		teams = league.getTeams();
				
		// Iterate from first team in league to second to last team in league
		for(int i = 0; i < teams.size() - 1; i++){
			// Make sure this team's rush_yds are not less than the next teams
			assertTrue(!(teams.get(i).getRushYds() < teams.get(i+1).getRushYds()));
//			if(teams.get(i).getRushYds() < teams.get(i+1).getRushYds()){
//				// If not then fail
//				fail("Team's were not sorted correctly by rushing yards\n");
//			}
		}
		
		// Sort teams by rush_tds
		league.sort(4);
				
		// Get this leagues teams array
		teams = league.getTeams();
				
		// Iterate from first team in league to second to last team in league
		for(int i = 0; i < teams.size() - 1; i++){
			// Make sure this team's rush_tds are not less than the next teams
			assertTrue(!(teams.get(i).getRushTds() < teams.get(i+1).getRushTds()));
//			if(teams.get(i).getRushTds() < teams.get(i+1).getRushTds()){
//				// If not then fail
//				fail("Team's were not sorted correctly by rushing touchdowns\n");
//			}
		}
		
		// Sort teams by rec_yds
		league.sort(5);
				
		// Get this leagues teams array
		teams = league.getTeams();
				
		// Iterate from first team in league to second to last team in league
		for(int i = 0; i < teams.size() - 1; i++){
			// Make sure this team's rec_yds are not less than the next teams
			assertTrue(!(teams.get(i).getRecYds() < teams.get(i+1).getRecYds()));
//			if(teams.get(i).getRecYds() < teams.get(i+1).getRecYds()){
//				// If not then fail
//				fail("Team's were not sorted correctly by receiving  yards\n");
//			}
		}
		
		// Sort teams by rec_tds
		league.sort(6);
				
		// Get this leagues teams array
		teams = league.getTeams();
				
		// Iterate from first team in league to second to last team in league
		for(int i = 0; i < teams.size() - 1; i++){
			// Make sure this team's rec_tds are not less than the next teams
			assertTrue(!(teams.get(i).getRecTds() < teams.get(i+1).getRecTds()));
//			if(teams.get(i).getRecTds() < teams.get(i+1).getRecTds()){
//				// If not then fail
//				fail("Team's were not sorted correctly by receiving touchdowns\n");
//			}
		}
		
		// Sort teams by fumbles
		league.sort(7);
				
		// Get this leagues teams array
		teams = league.getTeams();
				
		// Iterate from first team in league to second to last team in league
		for(int i = 0; i < teams.size() - 1; i++){
			// Make sure this team's fumbles are not more than the next teams
			assertTrue(!(teams.get(i).getFumbles() > teams.get(i+1).getFumbles()));
//			if(teams.get(i).getFumbles() > teams.get(i+1).getFumbles()){
//				// If not then fail
//				fail("Team's were not sorted correctly by fumbles\n");
//			}
		}
		
		// Sort teams by ret_tds
		league.sort(8);
				
		// Get this leagues teams array
		teams = league.getTeams();
				
		// Iterate from first team in league to second to last team in league
		for(int i = 0; i < teams.size() - 1; i++){
			// Make sure this team's ret_tds are not less than the next teams
			assertTrue(!(teams.get(i).getRetTds() < teams.get(i+1).getRetTds()));
//			if(teams.get(i).getRetTds() < teams.get(i+1).getRetTds()){
//				// If not then fail
//				fail("Team's were not sorted correctly by return touchdowns\n");
//			}
		}
		
		// Sort teams by def_tds
		league.sort(9);
				
		// Get this leagues teams array
		teams = league.getTeams();
				
		// Iterate from first team in league to second to last team in league
		for(int i = 0; i < teams.size() - 1; i++){
			// Make sure this team's def_tds are not less than the next teams
			assertTrue(!(teams.get(i).getDefTds() < teams.get(i+1).getDefTds()));
//			if(teams.get(i).getDefTds() < teams.get(i+1).getDefTds()){
//				// If not then fail
//				fail("Team's were not sorted correctly by defensive touchdowns\n");
//			}
		}
		
		// Sort teams by def_picks
		league.sort(10);
				
		// Get this leagues teams array
		teams = league.getTeams();
				
		// Iterate from first team in league to second to last team in league
		for(int i = 0; i < teams.size() - 1; i++){
			// Make sure this team's def_picks are not less than the next teams
			assertTrue(!(teams.get(i).getDefPicks() < teams.get(i+1).getDefPicks()));
//			if(teams.get(i).getDefPicks() < teams.get(i+1).getDefPicks()){
//				// If not then fail
//				fail("Team's were not sorted correctly by defensive picks\n");
//			}
		}
		
		// Sort teams by def_fumbles
		league.sort(11);
				
		// Get this leagues teams array
		teams = league.getTeams();
				
		// Iterate from first team in league to second to last team in league
		for(int i = 0; i < teams.size() - 1; i++){
			// Make sure this team's def_fumbles are not less than the next teams
			assertTrue(!(teams.get(i).getDefFumbles() < teams.get(i+1).getDefFumbles()));
//			if(teams.get(i).getDefFumbles() < teams.get(i+1).getDefFumbles()){
//				// If not then fail
//				fail("Team's were not sorted correctly by defensive fumbles\n");
//			}
		}
		
		// Sort teams by sacks
		league.sort(12);
				
		// Get this leagues teams array
		teams = league.getTeams();
				
		// Iterate from first team in league to second to last team in league
		for(int i = 0; i < teams.size() - 1; i++){
			// Make sure this team's sacks are not less than the next teams
			assertTrue(!(teams.get(i).getSacks() < teams.get(i+1).getSacks()));
//			if(teams.get(i).getSacks() < teams.get(i+1).getSacks()){
//				// If not then fail
//				fail("Team's were not sorted correctly by sacks\n");
//			}
		}
		
		// Sort teams by blocks
		league.sort(13);
				
		// Get this leagues teams array
		teams = league.getTeams();
				
		// Iterate from first team in league to second to last team in league
		for(int i = 0; i < teams.size() - 1; i++){
			// Make sure this team's blocks are not less than the next teams
			assertTrue(!(teams.get(i).getBlocks() < teams.get(i+1).getBlocks()));
//			if(teams.get(i).getBlocks() < teams.get(i+1).getBlocks()){
//				// If not then fail
//				fail("Team's were not sorted correctly by blocks\n");
//			}
		}
		
		// Sort teams by safeties
		league.sort(14);
				
		// Get this leagues teams array
		teams = league.getTeams();
				
		// Iterate from first team in league to second to last team in league
		for(int i = 0; i < teams.size() - 1; i++){
			// Make sure this team's safeties are not less than the next teams
			assertTrue(!(teams.get(i).getSafeties() < teams.get(i+1).getSafeties()));
//			if(teams.get(i).getSafeties() < teams.get(i+1).getSafeties()){
//				// If not then fail
//				fail("Team's were not sorted correctly by safeties\n");
//			}
		}
		
		// Sort teams by pa
		league.sort(15);
				
		// Get this leagues teams array
		teams = league.getTeams();
				
		// Iterate from first team in league to second to last team in league
		for(int i = 0; i < teams.size() - 1; i++){
			// Make sure this team's pa are not more than the next teams
			assertTrue(!(teams.get(i).getPA() > teams.get(i+1).getPA()));
//			if(teams.get(i).getPA() > teams.get(i+1).getPA()){
//				// If not then fail
//				fail("Team's were not sorted correctly by points against\n");
//			}
		}
		
		// Sort teams by ya
		league.sort(16);
				
		// Get this leagues teams array
		teams = league.getTeams();
				
		// Iterate from first team in league to second to last team in league
		for(int i = 0; i < teams.size() - 1; i++){
			// Make sure this team's ya are not more than the next teams
			assertTrue(!(teams.get(i).getYA() > teams.get(i+1).getYA()));
//			if(teams.get(i).getYA() > teams.get(i+1).getYA()){
//				// If not then fail
//				fail("Team's were not sorted correctly by yards against\n");
//			}
		}
		
		// Sort teams by pat
		league.sort(17);
				
		// Get this leagues teams array
		teams = league.getTeams();
				
		// Iterate from first team in league to second to last team in league
		for(int i = 0; i < teams.size() - 1; i++){
			// Make sure this team's pat are not less than the next teams\
			assertTrue(!(teams.get(i).getPAT() < teams.get(i+1).getPAT()));
//			if(teams.get(i).getPAT() < teams.get(i+1).getPAT()){
//				// If not then fail
//				fail("Team's were not sorted correctly by PAT\n");
//			}
		}
		
		// Sort teams by fg
		league.sort(18);
				
		// Get this leagues teams array
		teams = league.getTeams();
				
		// Iterate from first team in league to second to last team in league
		for(int i = 0; i < teams.size() - 1; i++){
			// Make sure this team's fg0 are not less than the next teams
			assertTrue(!(teams.get(i).getFG() < teams.get(i+1).getFG()));
//			if(teams.get(i).getFG() < teams.get(i+1).getFG()){
//				// If not then fail
//				fail("Team's were not sorted correctly by short field goals\n");
//			}
		}
		
		// Sort teams by misses
		league.sort(19);
				
		// Get this leagues teams array
		teams = league.getTeams();
				
		// Iterate from first team in league to second to last team in league
		for(int i = 0; i < teams.size() - 1; i++){
			// Make sure this team's misses are not more than the next teams
			assertTrue(!(teams.get(i).getMisses() > teams.get(i+1).getMisses()));
//			if(teams.get(i).getMisses() > teams.get(i+1).getMisses()){
//				// If not then fail
//				fail("Team's were not sorted correctly by misses\n");
//			}
		}
		
		// Sort teams by points
		league.sort(20);
				
		// Get this leagues teams array
		teams = league.getTeams();
				
		// Iterate from first team in league to second to last team in league
		for(int i = 0; i < teams.size() - 1; i++){
			// Make sure this team's points are not less than the next teams
			assertTrue(!(teams.get(i).calculatePoints() < teams.get(i+1).calculatePoints()));
//			if(teams.get(i).calculatePoints() < teams.get(i+1).calculatePoints()){
//				// If not then fail
//				fail("Team's were not sorted correctly by points\n");
//			}
		}
	}

}
